"""
Copyright (C)2010 Humanetrix Foundation, Inc.

This file is a part of the GROUP MATCH PYTHON. GROUP MATCH PYTHON is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses>.

About this Project
------------------
GROUP MATCH PYTHON was the outcome of Dev Derby (http://devderby.com), held in Bloomington, Indiana on September 11, 2010. The challenge was to build a system to allow groups to offer services to non-profits and manage feedback on prior volunteer efforts, initiating the flow of quality human resources to the organizations that need them. This had to be done in one six-hour session.

Five teams representing different programming languages competed in this first event. Team Python includes:

	Charles Brandt, Team Lead 
	Rajesh Gollapudi 
	Vijay Lulla 
	Josh Dolitsky

Questions or comments should be directed to info@devderby.com.
"""

from google.appengine.ext import db
from google.appengine.ext import webapp

global skill_list
global user_skill_list
skill_list = open('skill_list.txt', 'r').readlines()
user_skill_list = list(skill_list)

for i in range(len(skill_list)):
	user_skill_list[i] = skill_list[i].strip()
	
for i in range(len(skill_list)):
	skill_list[i] = skill_list[i].strip().lower()

class SkillGroup(db.Model):
	skill_list = db.StringProperty(required=True)
	custom_skills = db.StringListProperty()
	
	def __init__(self, **kwargs):
		if not kwargs.has_key('skill_list'):
			kwargs['skill_list'] = "0"*31
		if not kwargs.has_key('custom_skills'):
			kwargs['custom_skills'] = []
		db.Model.__init__(self, **kwargs)
	def set_skill_list(self, stri):
		self.skill_list = stri
	def set_skill(self, skill, add=1):
		if skill.lower == 'none':
			return
		
		global skill_list
		if skill.lower() in skill_list:
			self.skill_list[skill_list.index(skill.lower())] = `add`
		else:
			if add:
				if not skill.strip() in self.custom_skills: self.custom_skills.append(skill.strip())
			else:
				if skill.strip() in self.custom_skills: self.custom_skills.remove(skill.strip())
	def get_skill(self, skill):
		global skill_list
		
		if skill.lower() == 'none':
			return True
		
		if skill.lower() in skill_list:
			return bool(int(self.skill_list[skill_list.index(skill.lower())]))
		else:
			return skill.strip in self.custom_skills
	def get_skills(self):
		global user_skill_list
		
		skills = []
		for i in range(31):
			if bool(int(self.skill_list[i])): skills.append(user_skill_list[i])
		skills.extend(self.custom_skills)
		if not skills:
			skills.append('None')
		return skills
	def get_skills_string(self):
		return ', '.join(self.get_skills())
class ListSkill(webapp.RequestHandler):
  def get(self):
    pass

class NewSkill(webapp.RequestHandler):
  def post(self):
    pass
